import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneRandomValue, findOneValue } from '../../public'

type ModelProps = {
  id: number
  name: string
  description: string // 介绍
  constitution: number
  spirit: number
  strength: number
  intelligence: number
  agility: number
  perception: number
  charm: number
  luck: number
  atk: number
  matk: number
  def: number
  mdef: number
  hp_max: number
  mp_max: number
  hit: number
  dodge: number
  crit: number
  crit_dmg: number
  crit_avoid: number
  crit_resist: number
  speed: number
  tenacity: number
  hp_recover: number
  mp_recover: number
  extra_effect: string
}

class equipment_list extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

equipment_list.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
      comment: '自增主键'
    },
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      unique: true,
      comment: '武器名称'
    },
    description: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '介绍'
    },
    constitution: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '体质'
    },
    spirit: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '精神'
    },
    strength: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '力量'
    },
    intelligence: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '智力'
    },
    agility: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '敏捷'
    },
    perception: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '感知'
    },
    charm: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魅力'
    },
    luck: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '幸运'
    },
    hp_max: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '生命上限'
    },
    mp_max: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔力上限'
    },
    atk: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '物理攻击力'
    },
    matk: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔法攻击力'
    },
    def: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '物理防御力'
    },
    mdef: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔法防御力'
    },
    hit: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '命中'
    },
    dodge: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '闪避'
    },
    crit: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴击'
    },
    crit_dmg: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴伤'
    },
    crit_avoid: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴免'
    },
    crit_resist: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴抗'
    },
    speed: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '速度'
    },
    tenacity: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '韧性'
    },
    hp_recover: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '生命恢复'
    },
    mp_recover: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔力恢复'
    },
    extra_effect: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '额外效果'
    }
  },
  {
    sequelize,
    tableName: 'equipment_list',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: true,
        fields: ['id']
      },
      {
        unique: true,
        fields: ['name']
      }
    ]
  }
)

export { equipment_list }
